package com.ncs.leisure.overall.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.ncs.leisure.overall.business.ContactBusiness;

public class FormatWeb implements ServletContextListener{


	//加载系统,用户统一平台
	
	public void contextInitialized(ServletContextEvent arg0) {

		try {
			
			ContactBusiness contact = (ContactBusiness) arg0.getServletContext().getAttribute("NCSLeisure");
			
		 	if(contact==null||contact.equals("")){
		 		
		 		ApplicationContext ctx=null;
		 		
		 		contact=null;																									
		 	 	
				ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
			 
				contact = (ContactBusiness)ctx.getBean("contactBusiness");

				arg0.getServletContext().setAttribute("NCSLeisure", contact);
				
			}
		 	
			System.out.println("加载NCSLeisure初始化参数，成功！");
		 	
		}catch(Exception e) {
			
			System.out.println("加载NCSLeisure初始化参数，失败！");
		
			e.printStackTrace();
		
		}
		
	}
	
	//销毁统一认证平台变量
	
	public void contextDestroyed(ServletContextEvent arg0) {
		
		arg0.getServletContext().removeAttribute("NCSLeisure");
		
		System.out.println("加载NCSLeisure参数注销，成功！");
		
	}

}
